package Action.user;

import Bean.Log.SystemLogEntity;
import Bean.Log.UserLogEntity;
import com.opensymphony.xwork2.ActionSupport;
import org.hibernate.Session;
import tools.HibernateTools;

import java.util.LinkedList;
import java.util.List;

public class SysInfoManage extends ActionSupport {
    String userkey;
    String syskey;
    LinkedList<String> sysLogs=new LinkedList<>();
    LinkedList<String> userLogs=new LinkedList<>();
    public String showAll(){
        List<UserLogEntity> userLogEntities;
        List<SystemLogEntity> systemLogEntities;
        Session session= HibernateTools.getSession();
        //未知异常:事务经常开启失败
        //2021年5月25日--工具类升级后此问题低发


        if (userkey==null||userkey.equals(""))
             userLogEntities=session.createQuery("from UserLogEntity order by id desc  ").setMaxResults(50).getResultList();
        else
            userLogEntities=session.createQuery("from UserLogEntity where flag=? order by id desc  ").setParameter(0, userkey).setMaxResults(50).getResultList();
        if (syskey==null||syskey.equals(""))
            systemLogEntities=session.createQuery("from  SystemLogEntity order by id desc  ").setMaxResults(50).getResultList();
        else
            systemLogEntities=session.createQuery("from  SystemLogEntity where flag=? order by id desc  ").setParameter(0, syskey).setMaxResults(50).getResultList();
        for (UserLogEntity userLogEntity : userLogEntities) {
            userLogs.addLast(userLogEntity.BuildLog());
        }
        for (SystemLogEntity systemLogEntity : systemLogEntities) {
            sysLogs.addLast(systemLogEntity.BuildLog());
        }
        HibernateTools.commit(session);
        return SUCCESS;
    }

    public LinkedList<String> getSysLogs() {
        return sysLogs;
    }

    public void setSysLogs(LinkedList<String> sysLogs) {
        this.sysLogs = sysLogs;
    }

    public LinkedList<String> getUserLogs() {
        return userLogs;
    }

    public void setUserLogs(LinkedList<String> userLogs) {
        this.userLogs = userLogs;
    }

    public String getUserkey() {
        return userkey;
    }

    public void setUserkey(String userkey) {
        this.userkey = userkey;
    }

    public String getSyskey() {
        return syskey;
    }

    public void setSyskey(String syskey) {
        this.syskey = syskey;
    }
}
